﻿/**  PACS v1.0
* JC_SystemUserInfo.cs
*
* 类 名： JC_SystemUserInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:32   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_SystemUserInfo
	/// </summary>
	public partial class JC_SystemUserInfo
	{
		public JC_SystemUserInfo()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from JC_SystemUserInfo");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_SystemUserInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.YongHuXingMing != null)
			{
				strSql1.Append("YongHuXingMing,");
				strSql2.Append("'"+model.YongHuXingMing+"',");
			}
			if (model.XingBie != null)
			{
				strSql1.Append("XingBie,");
				strSql2.Append("'"+model.XingBie+"',");
			}
			if (model.YiYuanID != null)
			{
				strSql1.Append("YiYuanID,");
				strSql2.Append("'"+model.YiYuanID+"',");
			}
			if (model.ZhiWei != null)
			{
				strSql1.Append("ZhiWei,");
				strSql2.Append("'"+model.ZhiWei+"',");
			}
			if (model.GongHao != null)
			{
				strSql1.Append("GongHao,");
				strSql2.Append("'"+model.GongHao+"',");
			}
			if (model.BianMA != null)
			{
				strSql1.Append("BianMA,");
				strSql2.Append("'"+model.BianMA+"',");
			}
			if (model.JiaTingZhuZhi != null)
			{
				strSql1.Append("JiaTingZhuZhi,");
				strSql2.Append("'"+model.JiaTingZhuZhi+"',");
			}
			if (model.HuJiSuoZaiDi != null)
			{
				strSql1.Append("HuJiSuoZaiDi,");
				strSql2.Append("'"+model.HuJiSuoZaiDi+"',");
			}
			if (model.XianZhuZhi != null)
			{
				strSql1.Append("XianZhuZhi,");
				strSql2.Append("'"+model.XianZhuZhi+"',");
			}
			if (model.XueLi != null)
			{
				strSql1.Append("XueLi,");
				strSql2.Append("'"+model.XueLi+"',");
			}
			if (model.ChuShengRiQI != null)
			{
				strSql1.Append("ChuShengRiQI,");
				strSql2.Append("'"+model.ChuShengRiQI+"',");
			}
			if (model.ZhiWeiLeiBie != null)
			{
				strSql1.Append("ZhiWeiLeiBie,");
				strSql2.Append("'"+model.ZhiWeiLeiBie+"',");
			}
			if (model.ShenFenNO != null)
			{
				strSql1.Append("ShenFenNO,");
				strSql2.Append("'"+model.ShenFenNO+"',");
			}
			strSql.Append("insert into JC_SystemUserInfo(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_SystemUserInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_SystemUserInfo set ");
			if (model.YongHuXingMing != null)
			{
				strSql.Append("YongHuXingMing='"+model.YongHuXingMing+"',");
			}
			else
			{
				strSql.Append("YongHuXingMing= null ,");
			}
			if (model.XingBie != null)
			{
				strSql.Append("XingBie='"+model.XingBie+"',");
			}
			else
			{
				strSql.Append("XingBie= null ,");
			}
			if (model.YiYuanID != null)
			{
				strSql.Append("YiYuanID='"+model.YiYuanID+"',");
			}
			else
			{
				strSql.Append("YiYuanID= null ,");
			}
			if (model.ZhiWei != null)
			{
				strSql.Append("ZhiWei='"+model.ZhiWei+"',");
			}
			else
			{
				strSql.Append("ZhiWei= null ,");
			}
			if (model.GongHao != null)
			{
				strSql.Append("GongHao='"+model.GongHao+"',");
			}
			else
			{
				strSql.Append("GongHao= null ,");
			}
			if (model.BianMA != null)
			{
				strSql.Append("BianMA='"+model.BianMA+"',");
			}
			else
			{
				strSql.Append("BianMA= null ,");
			}
			if (model.JiaTingZhuZhi != null)
			{
				strSql.Append("JiaTingZhuZhi='"+model.JiaTingZhuZhi+"',");
			}
			else
			{
				strSql.Append("JiaTingZhuZhi= null ,");
			}
			if (model.HuJiSuoZaiDi != null)
			{
				strSql.Append("HuJiSuoZaiDi='"+model.HuJiSuoZaiDi+"',");
			}
			else
			{
				strSql.Append("HuJiSuoZaiDi= null ,");
			}
			if (model.XianZhuZhi != null)
			{
				strSql.Append("XianZhuZhi='"+model.XianZhuZhi+"',");
			}
			else
			{
				strSql.Append("XianZhuZhi= null ,");
			}
			if (model.XueLi != null)
			{
				strSql.Append("XueLi='"+model.XueLi+"',");
			}
			else
			{
				strSql.Append("XueLi= null ,");
			}
			if (model.ChuShengRiQI != null)
			{
				strSql.Append("ChuShengRiQI='"+model.ChuShengRiQI+"',");
			}
			else
			{
				strSql.Append("ChuShengRiQI= null ,");
			}
			if (model.ZhiWeiLeiBie != null)
			{
				strSql.Append("ZhiWeiLeiBie='"+model.ZhiWeiLeiBie+"',");
			}
			else
			{
				strSql.Append("ZhiWeiLeiBie= null ,");
			}
			if (model.ShenFenNO != null)
			{
				strSql.Append("ShenFenNO='"+model.ShenFenNO+"',");
			}
			else
			{
				strSql.Append("ShenFenNO= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_SystemUserInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_SystemUserInfo ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_SystemUserInfo GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,YongHuXingMing,XingBie,YiYuanID,ZhiWei,GongHao,BianMA,JiaTingZhuZhi,HuJiSuoZaiDi,XianZhuZhi,XueLi,ChuShengRiQI,ZhiWeiLeiBie,ShenFenNO ");
			strSql.Append(" from JC_SystemUserInfo ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.JC_SystemUserInfo model=new Pacs.Model.JC_SystemUserInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_SystemUserInfo DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_SystemUserInfo model=new Pacs.Model.JC_SystemUserInfo();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["YongHuXingMing"]!=null)
				{
					model.YongHuXingMing=row["YongHuXingMing"].ToString();
				}
				if(row["XingBie"]!=null)
				{
					model.XingBie=row["XingBie"].ToString();
				}
				if(row["YiYuanID"]!=null)
				{
					model.YiYuanID=row["YiYuanID"].ToString();
				}
				if(row["ZhiWei"]!=null)
				{
					model.ZhiWei=row["ZhiWei"].ToString();
				}
				if(row["GongHao"]!=null)
				{
					model.GongHao=row["GongHao"].ToString();
				}
				if(row["BianMA"]!=null)
				{
					model.BianMA=row["BianMA"].ToString();
				}
				if(row["JiaTingZhuZhi"]!=null)
				{
					model.JiaTingZhuZhi=row["JiaTingZhuZhi"].ToString();
				}
				if(row["HuJiSuoZaiDi"]!=null)
				{
					model.HuJiSuoZaiDi=row["HuJiSuoZaiDi"].ToString();
				}
				if(row["XianZhuZhi"]!=null)
				{
					model.XianZhuZhi=row["XianZhuZhi"].ToString();
				}
				if(row["XueLi"]!=null)
				{
					model.XueLi=row["XueLi"].ToString();
				}
				if(row["ChuShengRiQI"]!=null && row["ChuShengRiQI"].ToString()!="")
				{
					model.ChuShengRiQI=DateTime.Parse(row["ChuShengRiQI"].ToString());
				}
				if(row["ZhiWeiLeiBie"]!=null)
				{
					model.ZhiWeiLeiBie=row["ZhiWeiLeiBie"].ToString();
				}
				if(row["ShenFenNO"]!=null)
				{
					model.ShenFenNO=row["ShenFenNO"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,YongHuXingMing,XingBie,YiYuanID,ZhiWei,GongHao,BianMA,JiaTingZhuZhi,HuJiSuoZaiDi,XianZhuZhi,XueLi,ChuShengRiQI,ZhiWeiLeiBie,ShenFenNO ");
			strSql.Append(" FROM JC_SystemUserInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,YongHuXingMing,XingBie,YiYuanID,ZhiWei,GongHao,BianMA,JiaTingZhuZhi,HuJiSuoZaiDi,XianZhuZhi,XueLi,ChuShengRiQI,ZhiWeiLeiBie,ShenFenNO ");
			strSql.Append(" FROM JC_SystemUserInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_SystemUserInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_SystemUserInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

